package com.example.designhbwxz.book.controller;

import com.example.designhbwxz.book.pojo.UserInfo;
import com.example.designhbwxz.book.service.UserBridgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 桥接模式 - 用户控制层
 *
 * @author shenzw
 * @date 2023/10/23
 */
@RestController
@RequestMapping("/bridge")
public class UserBridgeController {

    @Autowired
    private UserBridgeService userBridgeService;

    @Value("${gitee.state}")
    private String gitee;

    /**
     * 用户登陆
     *
     * @param account  账号
     * @param password 密码
     * @return String
     */
    @PostMapping("/login")
    public String login(String account, String password) {
        return userBridgeService.login(account, password);
    }

    /**
     * 注册用户
     *
     * @param userInfo 注册用户信息
     * @return String
     */
    @PostMapping("/register")
    public String register(@RequestBody UserInfo userInfo) {
        return userBridgeService.register(userInfo);
    }

    /**
     * Gitee 平台回调地址接口，并携带 code 参数和 state 参数
     *
     * @param request HttpServletRequest
     * @return String
     */
    @GetMapping("/gitee")
    public String gitee(HttpServletRequest request) {
        return userBridgeService.login3rd(request, gitee);
    }
}
